package cn.ppool.xmlmapper.utils;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

public class ResponseDTO<T> implements Serializable {

    public enum Type_enum {
        ok, fail
    }


    @Getter
    @Setter
    private String code;
    @Getter
    @Setter
    private String msg;
    @Getter
    @Setter
    private Type_enum type;
    @Getter
    @Setter
    private T Result;



    // Object Function

    public ResponseDTO<T> setOK(Integer code, String msg) {
        this.code = code.toString();
        this.msg = msg;
        this.type = Type_enum.ok;
        return this;
    }

    public ResponseDTO<T> setOK(Integer code, String msg, T result) {
        this.code = code.toString();
        this.msg = msg;
        this.Result = result;
        this.type = Type_enum.ok;
        return this;
    }


    public ResponseDTO<T> setFail(Integer code, String msg) {
        this.code = code.toString();
        this.msg = msg;
        this.type = Type_enum.fail;
        return this;
    }

    public ResponseDTO<T> setFail(Integer code, String msg, T result) {
        this.code = code.toString();
        this.msg = msg;
        this.Result = result;
        this.type = Type_enum.fail;
        return this;
    }


    // static function
    public static <G> ResponseDTO<G> OK(Integer code, String msg) {
        return new ResponseDTO<G>().setOK(code, msg);
    }

    public static <G> ResponseDTO<G> OK(Integer code, String msg, G result) {
        return new ResponseDTO<G>().setOK(code, msg, result);
    }


    public static <G> ResponseDTO<G> Fail(Integer code, String msg) {
        return new ResponseDTO<G>().setFail(code, msg);
    }


    public static <G> ResponseDTO<G> Fail(Integer code, String msg, G result) {
        return new ResponseDTO<G>().setFail(code, msg, result);
    }


}
